package com.web.service.impl;


import com.web.entity.PageVO;
import com.web.entity.Student;
import com.web.mapper.StudentMapper;
import com.web.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: XiangHu
 * @date: 2025年02月28日 16:55
 * @describe:
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentMapper studentmapper;

    @Override
    public List<Student> findAllStudents() {
        return studentmapper.findstudents();
    }

    @Override
    public int addStudent(Student student) {
       return studentmapper.insertstudent(student);

    }


   @Override
   public int updateStudent(Student student) {
       // 调用 DAO 层的更新方法
       return studentmapper.updatestudent(student);  // 确保 DAO 方法返回更新的记录数
   }


    @Override
    public int deleteStudent(int id) {
        studentmapper.removestudent(id);
        return id;
    }

    @Override
    public PageVO findStudentPage(int current, int pageSize) {
    int count = studentmapper.selectStudentCount();// 通过实例调用

        int start = (current - 1) * pageSize;
        //分页查询学生集合
        List<Student> students = studentmapper.selectStudentPage(start,pageSize);
        return new PageVO(current,pageSize,count,students);

    }
}